<html>
<body>
	<h2>Hello World!</h2>
	<table>
		<tr>
			<td>用户名</td>
			<td><input type="text" name="username" id="username" /></td>
		</tr>
		<tr>
			<td>密码</td>
			<td><input type="password" name="password" id="password" /></td>
		</tr>
		<tr>
			<td><input type="button" value="提交" onclick="post_data()"></td>
		</tr>
	</table>
	<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
	<script src="js/rsa.js" type="text/javascript"></script>
	<script>
	//定义公钥
	var public_key ;
	$(//获取公钥
		$.ajax({
            url:'public_key',
            type:'post',
            success:function(res){
                if(res.code==200){
                	public_key = res.public_key;
                }
            }
        })
	)
	//登录
    function post_data(){
    	var encrypt=new JSEncrypt();
    	encrypt.setPublicKey(public_key);
    	var rsa_password　=　encrypt.encrypt($('#password').val());
    	$.ajax({
    		url:'login',
    		type:'post',
    		data:{'username':$('#username').val(),'rsa_password':rsa_password},
    		success:function(res){
    			console.log(res);
    		}
    	})
    }
    </script>
</body>
</html>
